|
|
|
|
|
|
|
DtrBits = DCB1.Bits1 And &H30 |
|
|
|
|
|
|
|
|
Now, how do you get the two bits to the point where you can compare them with the three constants? You need to shift them so that, instead of bits 4 and 5, they will be located at bits 0 and 1. You can shift bits one value to the right by dividing the number by 2. |
|
|
|
|
|
|
|
|
Want proof? Check out the table below. |
|
|
|
|
| NUMBER | IN BINARY | DIVIDED BY 2 | IN BINARY | | 16 | 10000 | 8 | 1000 | | 8 | 1000 | 4 | 100 | | 4 | 100 | 2 | 10 | | 2 | 10 | 1 | 1 |
|
|
|
|
|
|
Dividing by 2 shifts bits to the right. Multiplying by 2 shifts bits to the left. The only case you have to watch for is the high bit (bit 31 in a long variable), where you can run into an overflow situation. But that doesn't apply to this case because the high bit is not used. |
|
|
|
|
|
|
|
|
For the fDtrControl bits, we need to shift the DtrBits value 4 bits to the right, as follows: |
|
|
|
|
|
|
|
|
DtrValue = DtrBits / &H10000 |
|
|
|
|
|
|
|
|
To check whether DTR control is enabled, you can compare the value with the constant, as follows: |
|
|
|
|
|
|
|
|
If DtrValue = DTR_CONTROL ENABLE Then
' DTR CONTROL ENABLE is set
End If |
|
|
|
|
|
|
|
|
Let's say you want to set the fDtrControl bits to DTR_CONTROL_HANDSHAKE. To do this, you must reverse the process, as follows: |
|
|
|
|
|
|
|
|
DtrValue = DTR_CONTROL_HANDSHAKE ' Set the value
DtrBits = DtrValue * &H10000 ' Shift the bits to the left
DCB1.Bits1 = DCB1.Bits1 And (Not &H30) ' Clear the two bits
DCB1.Bits1 = DCB1.Bits lOr DtrBits ' Or in the desired value |
|
|
|
|
|
|
|
|
You may want to step through this process by writing out the values on paper for several values to see how it works. |
|
|
|
|
|